package com.wmyg.antifake.controller;

import com.wmyg.antifake.entity.Company;
import com.wmyg.antifake.service.CompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.security.Principal;

/**
 * @author 王卓逸
 * @program TODO
 * @description TODO
 * @create 2019-05-20
 */
@RestController
@RequestMapping(value = "/company")
@Api(description = "企业信息相关接口")
public class CompanyController {

    @Autowired
    CompanyService companyService;

    @ApiOperation(value = "完善资料", notes = "添加操作不能传入id", response = Boolean.class)
    @PreAuthorize("hasAuthority('company')")
    @PostMapping(value = "/company")
    public Boolean saveCompany(Company company, @ApiIgnore Principal principal) {
        return companyService.save(company, principal.getName());
    }

    @ApiOperation(value = "更改企业信息", notes = "更改操作必须传入id", response = Boolean.class)
    @PreAuthorize("hasAuthority('company')")
    @PutMapping(value = "/company")
    public Boolean updateCompany(Company company) {
        return companyService.save(company);
    }

}
